﻿using UnityEngine;
namespace Project
{
    /// <summary>
    /// 子弹枚举类,怪物和玩家公用一个子弹基类
    /// </summary>
    public enum BulletType
    {
        PlayerBullet,
        MonsterBullet,
    }
    public abstract class BaseBullet : MonoBehaviour
    {
        public BulletType type; //子弹类型
        public float attack; //伤害
        public float moveSpeed; //飞行速度
        public float destroyTime; //销毁时间,单位为秒
        protected Rigidbody2D rb;
        protected abstract void Attack(Collider2D collision);
        public virtual void OnFire(Vector2 dir)
        {
            rb.velocity = dir * moveSpeed;
        }
        protected virtual void Awake()
        {
            rb = GetComponent<Rigidbody2D>();
            Destroy(gameObject, destroyTime);
        }
        private void OnTriggerEnter2D(Collider2D collision)
        {
            Attack(collision);
        }

    }
}
